from django.shortcuts import render

from  rest_framework import viewsets

from  rest_framework import  mixins
# 是否登录
from  rest_framework.permissions import IsAuthenticated

from rest_framework_jwt.authentication import JSONWebTokenAuthentication

from rest_framework.authentication import SessionAuthentication

from .models import UserFav

from .serializers import UserFavSerializer


from utils.permissions import IsOwnerOrReadOnly
# Create your views here.


class UserFavViewSet(mixins.RetrieveModelMixin,mixins.DestroyModelMixin, mixins.CreateModelMixin,mixins.ListModelMixin,viewsets.GenericViewSet):
    serializer_class = UserFavSerializer
    authentication_classes = (JSONWebTokenAuthentication, SessionAuthentication)
    permission_classes = (IsAuthenticated,IsOwnerOrReadOnly)
    # 搜索的详情
    lookup_field = "goods_id"

    def get_queryset(self):
        return UserFav.objects.filter(user=self.request.user)